require(pacman)
p_load(tidytuesdayR, tidyverse, trashpanda, magick, sf, scales, janitor)
options(scipen = 999)Italian Industrial Production
Load Packages
Load Data
tuesdata <- tidytuesdayR::tt_load('2026-05-05')
food_beverages <- tuesdata$food_beverages
textiles <- tuesdata$textiles
transport <- tuesdata$transportPlot
plot <- food_beverages |>
clean_names() |>
select(year, coffee_substitute, beer) |>
pivot_longer(!year, names_to = "beverage", values_to = "value") |>
drop_na(value) |>
mutate(beverage = case_when(beverage == "beer" ~ "Beer",
beverage == "coffee_substitute" ~ "Coffee Substitute")) |>
ggplot(aes(x = year,
y = value)) +
geom_point() +
geom_line() +
facet_wrap(~beverage, scales = "free", ncol = 1) +
scale_y_continuous(labels = scales::label_comma()) +
scale_x_continuous(breaks = scales::breaks_width(5)) +
labs(x = "Year", y = "Quintals (100 kg)",
title = "Industrial Production of Common Beverages in Italy, 1875-1985") +
theme_bw(base_size = 17) +
theme(
plot.margin = margin(b = 10),
plot.title = element_text(face = "bold", size = 25, hjust = 0),
strip.text = element_text(size = 20, face = "bold")) +
add_caption_cwb()
# Save and display images
current_dir <- dirname(knitr::current_input())
plot_name <- "italian_beverage_production.png"
ggsave(plot = plot,
dpi = "screen",
width = 16,
height = 10,
device = ragg::agg_png,
filename = file.path(current_dir, plot_name))
# Read the big plot
img <- image_read(file.path(current_dir, plot_name))
# Force 16:9 aspect ratio with minimal padding
# Target size: 1200x675 px (16:9)
img_card <- image_scale(img, "1200x675") # scale to fit inside 16:9
img_card <- image_extent(
img_card,
geometry = "1200x675",
gravity = "center"
)
# Save as card preview
image_write(img_card, path = file.path(current_dir, "preview.png"))
knitr::include_graphics(
file.path(current_dir, plot_name)
)
Interestingly, there is a big increase in coffee substitute production during World War II. I discovered this was due to trade embargos imposed on Italy. Italians resorted to just about anything that could produce a hot beverage (e.g., barley, orzo) to make “coffee (source). On the other hand, beer production started to increase post-war and steadily climbed.
References
cite_packages(format = "rmd")Firke S (2024). janitor: Simple Tools for Examining and Cleaning Dirty Data. doi:10.32614/CRAN.package.janitor https://doi.org/10.32614/CRAN.package.janitor. R package version 2.2.1, https://CRAN.R-project.org/package=janitor.
Wickham H, Pedersen T, Seidel D (2025). scales: Scale Functions for Visualization. doi:10.32614/CRAN.package.scales https://doi.org/10.32614/CRAN.package.scales. R package version 1.4.0, https://CRAN.R-project.org/package=scales.
Pebesma E, Bivand R (2023). Spatial Data Science: With applications in R. Chapman and Hall/CRC. doi:10.1201/9780429459016 https://doi.org/10.1201/9780429459016. https://r-spatial.org/book/.
Pebesma E (2018). “Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal, 10(1), 439-446. doi:10.32614/RJ-2018-009 https://doi.org/10.32614/RJ-2018-009. https://doi.org/10.32614/RJ-2018-009.
Ooms J (2026). magick: Advanced Graphics and Image-Processing in R. doi:10.32614/CRAN.package.magick https://doi.org/10.32614/CRAN.package.magick. R package version 2.9.1, https://CRAN.R-project.org/package=magick.
Baril C (2026). trashpanda: Cole’s Personal Collection of R Functions, Themes, and Palettes. R package version 0.0.1, commit d16de29303b66b1398238885a35c8a8b1aaf077f, https://github.com/colebaril/trashpanda.
Grolemund G, Wickham H (2011). “Dates and Times Made Easy with lubridate.” Journal of Statistical Software, 40(3), 1-25. https://www.jstatsoft.org/v40/i03/.
Wickham H (2025). forcats: Tools for Working with Categorical Variables (Factors). doi:10.32614/CRAN.package.forcats https://doi.org/10.32614/CRAN.package.forcats. R package version 1.0.1, https://CRAN.R-project.org/package=forcats.
Wickham H (2025). stringr: Simple, Consistent Wrappers for Common String Operations. doi:10.32614/CRAN.package.stringr https://doi.org/10.32614/CRAN.package.stringr. R package version 1.6.0, https://CRAN.R-project.org/package=stringr.
Wickham H, François R, Henry L, Müller K, Vaughan D (2026). dplyr: A Grammar of Data Manipulation. doi:10.32614/CRAN.package.dplyr https://doi.org/10.32614/CRAN.package.dplyr. R package version 1.2.1, https://CRAN.R-project.org/package=dplyr.
Wickham H, Henry L (2026). purrr: Functional Programming Tools. doi:10.32614/CRAN.package.purrr https://doi.org/10.32614/CRAN.package.purrr. R package version 1.2.2, https://CRAN.R-project.org/package=purrr.
Wickham H, Hester J, Bryan J (2026). readr: Read Rectangular Text Data. doi:10.32614/CRAN.package.readr https://doi.org/10.32614/CRAN.package.readr. R package version 2.2.0, https://CRAN.R-project.org/package=readr.
Wickham H, Vaughan D, Girlich M (2025). tidyr: Tidy Messy Data. doi:10.32614/CRAN.package.tidyr https://doi.org/10.32614/CRAN.package.tidyr. R package version 1.3.2, https://CRAN.R-project.org/package=tidyr.
Müller K, Wickham H (2026). tibble: Simple Data Frames. doi:10.32614/CRAN.package.tibble https://doi.org/10.32614/CRAN.package.tibble. R package version 3.3.1, https://CRAN.R-project.org/package=tibble.
Wickham H (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. ISBN 978-3-319-24277-4. https://ggplot2.tidyverse.org.
Wickham H, Averick M, Bryan J, Chang W, McGowan LD, François R, Grolemund G, Hayes A, Henry L, Hester J, Kuhn M, Pedersen TL, Miller E, Bache SM, Müller K, Ooms J, Robinson D, Seidel DP, Spinu V, Takahashi K, Vaughan D, Wilke C, Woo K, Yutani H (2019). “Welcome to the tidyverse.” Journal of Open Source Software, 4(43), 1686. doi:10.21105/joss.01686 https://doi.org/10.21105/joss.01686.
Harmon J, Hughes E (2026). tidytuesdayR: Access the Weekly ‘TidyTuesday’ Project Dataset. doi:10.32614/CRAN.package.tidytuesdayR https://doi.org/10.32614/CRAN.package.tidytuesdayR. R package version 1.3.3, https://CRAN.R-project.org/package=tidytuesdayR.
Rinker TW, Kurkiewicz D (2018). pacman: Package Management for R. version 0.5.0, http://github.com/trinker/pacman.